package com.yyys.web.controller;

import com.yyys.web.entity.DRGoodsInfo;
import com.yyys.web.json.DRGoodsJson;
import com.yyys.web.repository.DRGoodsRepository;
import com.yyys.web.service.DRGoodsInfoService;
import com.yyys.web.service.DRInfoService;
import com.yyys.web.utils.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhengsenwen on 2017/7/1.
 */

@RestController
@RequestMapping("/user")
public class UserController {

    private static Logger logger = Logger.getLogger(UserController.class);

    @Autowired
    private DRInfoService drInfoService;

    @Autowired
    private DRGoodsInfoService drGoodsInfoService;

    @Autowired
    private DRGoodsRepository drGoodsRepository;

    /**
     * drGoodsInfo test
     */
    @RequestMapping(value = "/drgoodsinfo/{spFlavor}", method = RequestMethod.GET)
    public List<DRGoodsInfo> getByFlavor(Model model, @PathVariable String spFlavor) {
        return drGoodsRepository.findByspFlavor(spFlavor);
    }

    @RequestMapping(value = "/drgoods/{drId}", method = RequestMethod.GET)
    public List<String> getGoodsByDrid(Model model, @PathVariable Integer drId) {
        String rq = DateUtils.getCurrentDay();
        String cbName = DateUtils.getBreakfastLunchOrDinner();
        return drGoodsRepository.findSpClaseNameByDrId(drId, cbName, rq);
    }

    @RequestMapping(value = "/diningroom/{drId}/goods/{spId}", method = RequestMethod.GET)
    public List<DRGoodsJson> getGoodsByDrid(Model model, @PathVariable("drId") Integer drId, @PathVariable("spId") String spId) {
        List<DRGoodsJson> drGoodsJsonList = new ArrayList<>();
        try {
            drGoodsJsonList = drGoodsInfoService.getRecommendGoodBydrIdAndspId(drId, spId);
        } catch (Exception e) {
            logger.info("getGoodsByDrid:" + e.getMessage());
            e.printStackTrace();
        }
        return drGoodsJsonList;
    }

    @RequestMapping(value = "/best/meal/time/{drId}", method = RequestMethod.GET)
    public String getY(Model model, @PathVariable Integer drId) {
        return drInfoService.getRecommendedMealTime(drId);
    }

}